<?
include "header.php";
$P = new cMyPage;
$P->loadHeader();
$P->loadTitle("Welcome");
$locList = array();
$loc['url'] = '/index.php';
$loc['name'] = 'Home';
array_push($locList, $loc);
$P->loadLocation($locList);
$P->loadLinks();
$P->loadPreContent("News");

//Select topics from news forum ID = 2
$topic_news = $db->sql_query("SELECT * FROM `phpbb_topics` WHERE `forum_id` = '2' ORDER BY `topic_time` DESC ");

//Count number of news items
$news_total = $db->sql_affectedrows();

//Loop each news topic
while ($row = $db->sql_fetchrow($topic_news)){

//SQL to Select each news post
$post = $db->sql_query("SELECT * FROM `phpbb_posts`  WHERE `post_id` = '".$row['topic_first_post_id']."' ");

//Fetch a row of our selection of news
$post_data = $db->sql_fetchrow($post);
//var_dump($post_data);

//Store important fields
$comment_count = $row['topic_replies'];
$post_id = $post_data['topic_id'];
$subject = $post_data['post_subject'];
$posted_time = date("D M d, Y g:i a", $post_data['post_time']);
$poster_id = $post_data['poster_id'];

//Select username from users table
$f_user = $db->sql_query("SELECT username FROM `phpbb_users` WHERE `user_id` = '".$row['topic_poster']."'");
$r_user = $db->sql_fetchfield('username');

//Clean news text from BBCode
$text = generate_text_for_display($post_data['post_text'], $post_data['bbcode_uid'], $post_data['bbcode_bitfield'], '7');

?>
<div class="news_post">
<h2><a href="/forum/viewtopic.php?f=2&amp;t=<?=$post_id;?>"><?=$subject;?></a></h2>
Posted on <?=$posted_time;?> By <a href="/forum/memberlist.php?mode=viewprofile&amp;u=<?=$poster_id;?>"><?=$r_user;?></a> Comments <?=$comment_count;?><br />
<p><?=$text;?></p>
</div>
<?
}
?>
      
<?php //var_dump($user->data); ?>
<br /><br />
<?php 
//Test RPI function
//if( $P->isRPI() ) echo "true"; else echo "false"; ?>
    
<? 
/* ======== ENd Page Content ========== */
$P->loadPostContent(); $P->loadFooter(); 

?>